package com.gxa.web_admin.controller;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.R;
import com.gxa.modules.pojo.Customer;
import com.gxa.modules.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/customers")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 分页查询个人客户列表所有数据
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/findCustomerList")
    public JsonResult findCustomerList(Long currentPage, Long pageSize){
//        JsonResult jr = new JsonResult();
//        try{
//            long totalSize = customerService.count();
//            jr.setCount((int) totalSize);
//            Long start =(currentPage-1)*pageSize;
//            Long off = pageSize;
//            Page<Customer> page =new Page(start,off);
//            Page<Customer> customerPage = customerService.page(page);
//            jr.setCode(200);
//            jr.setMsg("查询成功");
//            jr.setData(customerPage);
//        }catch (Exception e){
//            e.printStackTrace();
//            jr.setCode(500);
//            jr.setMsg("网络炸了");
//        }
        return customerService.findCustomerList(pageSize,currentPage);
    }

    /**
     * 个人客户条件搜索
     * @param currentPage
     * @param pageSize
     * @param customer_name
     * @param phone
     * @param creation_time
     * @return
     */
    @GetMapping("/findCustomerListByCondition")
    public JsonResult findCustomerListByCondition(Long currentPage, Long pageSize, String customer_name, String phone, String creation_time){
        return customerService.findCustomerListByCondition(currentPage,pageSize,customer_name,phone,creation_time);
    }
    @GetMapping("/findCustomerById")
    public R findCustomerById(Integer id){
        return customerService.findCustomerById(id);
    }
    /**
     * 删除
     */
    @GetMapping("/delCustomerById")
    public R delCustomerById(Integer id){
        return customerService.delCustomerById(id);
    }

    /**
     * 添加客户信息
     * @param customer
     * @return
     */
    @PostMapping("/addCustomer")
    public R addCustomer(@RequestBody Customer customer){
        return customerService.addCustomer(customer);
    }

    /**
     * 修改客户信息
     * @param customer
     * @return
     */
    @PostMapping("/updateCustomer")
    public R updateCustomer(@RequestBody  Customer customer){
        return customerService.updateCustomer(customer);
    }
    /**
     * 修改审核按钮
     */
    @PostMapping("/updateCustomerByAuditStatus")
    public R updateCustomerByAuditStatus(@RequestBody Customer customer){
        return customerService.updateCustomerByAuditStatus(customer);
    }

    @PostMapping("/updateFile")
    public R uploadFile(@RequestBody MultipartFile file){
        return customerService.uploadFile(file);
    }
}
